package com.smalls.redshoes.ui.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.smalls.newvideotwo.R;
import com.smalls.redshoes.ui.orderstate.OrderState;
import com.smalls.redshoes.ui.orderstate.OrderStateAdapter;
import com.smalls.redshoes.ui.orderstate.OrderStateEnum;

import java.util.ArrayList;
import java.util.List;

public class OrderStateDialog extends Dialog {
	// fruitList用于存储数据
	private List<OrderState> orderList=new ArrayList<>();
	public OrderStateDialog(Context activity, int theme) {
		super(activity, theme);
		setTitle("订单状态");
	}


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setCancelable(true);
		setContentView(R.layout.layout_orderstate_dialog);
		initData();


		OrderStateAdapter adapter=new OrderStateAdapter(this.getContext(),R.layout.rs_orderstate_item,orderList);

		// 将适配器上的数据传递给listView
		ListView listView=(ListView)findViewById(R.id.list_content_view);
		listView.setAdapter(adapter);

		// 为ListView注册一个监听器，当用户点击了ListView中的任何一个子项时，就会回调onItemClick()方法
		// 在这个方法中可以通过position参数判断出用户点击的是那一个子项
		listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				OrderState order=orderList.get(position);
				Toast.makeText(getContext(),order.getState(),Toast.LENGTH_SHORT).show();
			}
		});
	}
	private void initData() {
		OrderState a=new OrderState(OrderStateEnum.OrderState_START);
		orderList.add(a);
		OrderState a1=new OrderState(OrderStateEnum.OrderState_ERROR);
		orderList.add(a1);
		OrderState a3=new OrderState(OrderStateEnum.OrderState_ERROR);
		orderList.add(a3);
		OrderState a4=new OrderState(OrderStateEnum.OrderState_COMPLELTE);
		orderList.add(a4);
		OrderState a5=new OrderState(OrderStateEnum.OrderState_COMPLELTE);
		orderList.add(a5);
	}
	private DialogButtonListener mPositiveBtnListener;

	public OrderStateDialog setPositiveButtonListener(DialogButtonListener l) {
		mPositiveBtnListener = l;
		return this;
	}

	private DialogButtonListener mNegativeBtnListener;

	public OrderStateDialog setNegativeButtonListener(DialogButtonListener l) {
		mNegativeBtnListener = l;
		return this;
	}

	private View.OnClickListener mDefaultBtnLsr = new View.OnClickListener() {
		public void onClick(View v) {
			if (v.getId() == R.id.btn_quit) {
				OrderStateDialog.this.dismiss();
			}
		}
	};

	public interface DialogButtonListener {
		void onClick(Dialog dlg, View v);
	}

}
